#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar('\n');
}

const int MAXN = 5010;

typedef struct {int v,nxt;}edge;

int n,m,dfn[MAXN],low[MAXN],tot,cnt,s,blo[MAXN],nodenum,to[MAXN];
int top,stk[MAXN],ans,h[MAXN];
edge e[MAXN];
bool vis[MAXN];

void link(int x,int y){e[++cnt] = edge{y,h[x]};h[x] = cnt;}

void dfs(int x){
	dfn[x] = low[x] = ++tot;vis[x] = 1;
	stk[++top] = x;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v;
		if(!dfn[y]) dfs(y),low[x] = min(low[x],low[y]);
		else if(vis[y]) low[x] = min(low[x],dfn[y]);
	}
	if(low[x] == dfn[x]){
		int y;++nodenum;
		do{
			y = stk[top--];
			vis[y] = 0;
			blo[y] = nodenum;
		}while(y != x);
	}
}

int main (){
	n = in,m = in,s = in;
	for(int i = 1;i <= m;i++){
		int x = in,y = in;
		link(x,y);
	}
	for(int i = 1;i <= n;i++) if(!dfn[i]) dfs(i);
	for(int x = 1;x <= n;x++){
		for(int i = h[x];i;i = e[i].nxt){
			int y = e[i].v;
			if(blo[x] == blo[y]) continue;
			to[blo[y]]++;
		}
	}
	for(int i = 1;i <= nodenum;i++) if(!to[i] and blo[s] != i) ans++;
	write(ans);
	return 0;
}
